//
//  MyRefreshView.swift
//  WeiBoSwift
//
//  Created by rong on 15/7/4.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit

class MyRefreshView: UIView {

    //覆盖在中间的view
    @IBOutlet weak var coverView: UIView!
    
    //下拉刷新的图标
    @IBOutlet weak var loadingIcon: UIImageView!
    
    //加载数据的图标
    @IBOutlet weak var downIcon: UIImageView!
    
    
    
    class func myRefreshView() -> MyRefreshView {
    
        return NSBundle.mainBundle().loadNibNamed("MyRefreshView", owner: nil, options: nil).last as! MyRefreshView
    }
    
    //旋转 下拉刷新的图标
    func rotateDownIcon(isClockWise: Bool)
    {
        var angle = M_PI
        angle += isClockWise ? -0.01 : 0.01
        UIView.animateWithDuration(1.0) { () -> Void in
            
            self.downIcon.transform = CGAffineTransformRotate(self.downIcon.transform, CGFloat(angle))
        }
    }
    
    //开启 加载数据 的 动画
    func startLoadingIconAnim()
    {
        coverView.hidden = true
        
        //定义动画
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        anim.repeatCount = MAXFLOAT
        anim.duration = 0.5
        
        loadingIcon.layer.addAnimation(anim, forKey: nil)
    }
    
    //结束 动画
    func stopLoadingIconAnim()
    {
        coverView.hidden = false
        loadingIcon.layer.removeAllAnimations()
    }

}
